package com.vichat.user.entity;


import com.vichat.common.constant.I18nConstant;
import com.vichat.common.exception.ViChatException;
import com.vichat.common.util.StringUtil;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.*;

/***************
 *author: autogen
 *version: 2018-12-01 10:55:19.284
 */
@Entity
@Table(name = "sn_resource", catalog = "ccsdb")
public class SnResource implements java.io.Serializable {

    private static final long serialVersionUID = 1L;


    public static final String TABLE = "sn_resource";

    /**
     * SN_ID
     */
    public static final String ALIAS_SN_ID = "sn_id";
    /**
     * SN
     */
    public static final String ALIAS_SN = "SN";
    /**
     * SN类型
     */
    public static final String ALIAS_SN_TYPE = "SN_TYPE";
    /**
     * 所属代理商编号，0 为 客服初始所有
     */
    public static final String ALIAS_AGENT_ID = "agent_id";
    /**
     * 数据状态 0 已用 1 未用
     */
    public static final String ALIAS_RES_STATE = "res_state";
    /**
     * 数据 0 无效 1 有效
     */
    public static final String ALIAS_STATE = "state";
    /**
     * 创建时间
     */
    public static final String ALIAS_CREATE_TIME = "create_time";
    /**
     * 修改时间
     */
    public static final String ALIAS_UPDATE_TIME = "update_time";


    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "sn_id", unique = true, nullable = false)
    public java.lang.Long snId;

    @Column(name = "SN")
    public java.lang.String sn;

    @Column(name = "SN_TYPE")
    public java.lang.String snType;

    @Column(name = "agent_id")
    public java.lang.Long agentId;

    @Column(name = "res_state")
    public java.lang.Long resState = 1l;

    @Column(name = "state")
    public java.lang.Long state = 1l;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "create_time")
    public java.util.Date createTime;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "update_time")
    public java.util.Date updateTime;


    public java.lang.Long getSnId() {
        return this.snId;
    }

    public void setSnId(java.lang.Long value) {
        this.snId = value;
    }

    public java.lang.String getSn() {
        return this.sn;
    }

    public void setSn(java.lang.String value) {
        this.sn = value;
    }

    public java.lang.String getSnType() {
        return this.snType;
    }

    public void setSnType(java.lang.String value) {
        this.snType = value;
    }

    public java.lang.Long getAgentId() {
        return this.agentId;
    }

    public void setAgentId(java.lang.Long value) {
        this.agentId = value;
    }

    public java.lang.Long getResState() {
        return this.resState;
    }

    public void setResState(java.lang.Long value) {
        this.resState = value;
    }

    public java.lang.Long getState() {
        return this.state;
    }

    public void setState(java.lang.Long value) {
        this.state = value;
    }

    public java.util.Date getCreateTime() {
        return this.createTime;
    }

    public void setCreateTime(java.util.Date value) {
        this.createTime = value;
    }

    public java.util.Date getUpdateTime() {
        return this.updateTime;
    }

    public void setUpdateTime(java.util.Date value) {
        this.updateTime = value;
    }


    public SnResource() {
    }

    public SnResource(boolean qryflag) {
        if (qryflag) {
            this.snId = null;
            this.sn = null;
            this.snType = null;
            this.agentId = null;
            this.resState = null;
            this.state = null;
            this.createTime = null;
            this.updateTime = null;
        }
    }


    public SnResource(
            java.lang.Long inSnId,
            java.lang.String inSn,
            java.lang.String inSnType,
            java.lang.Long inAgentId,
            java.lang.Long inResState,
            java.lang.Long inState,
            java.util.Date inCreateTime,
            java.util.Date inUpdateTime
    ) {
        super();
        this.snId = inSnId;
        this.sn = inSn;
        this.snType = inSnType;
        this.agentId = inAgentId;
        this.resState = inResState;
        this.state = inState;
        this.createTime = inCreateTime;
        this.updateTime = inUpdateTime;
    }


    @Transient
    private String ext1;

    public String getExt1() {
        return ext1;
    }

    public void setExt1(String ext1) {
        this.ext1 = ext1;
    }

    @Transient
    private String agentCompanyName;

    public String getAgentCompanyName() {
        return agentCompanyName;
    }

    public void setAgentCompanyName(String agentCompanyName) {
        this.agentCompanyName = agentCompanyName;
    }

    public static String checkSnResources(SnResource snResource) throws ViChatException {
        if (StringUtils.isNotBlank(snResource.getSn())) {
            if (StringUtil.isSpecialChar(snResource.getSn())) {
                return I18nConstant.error_imeiSpecialChar;
            }
            if (snResource.getSn().length() > 20) {
                return I18nConstant.error_imeiTooLong;
            }
        }
        if (StringUtils.isNotBlank(snResource.getSnType())) {
            if (StringUtil.isSpecialChar(snResource.getSnType())) {
                return I18nConstant.error_imeiTypeSpecialChar;
            }
            if (snResource.getSnType().length() > 20) {
                return I18nConstant.error_imeiTypeTooLong;
            }
        }
        return null;
    }
}

